﻿/*

  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  
           http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is AST'r Framework.
  
  The Initial Developer of the Original Code is
  ALCARAZ Marc (aka eKameleon) <vegas@ekameleon.net>.
  Portions created by the Initial Developer are Copyright (C) 2004-2007
  the Initial Developer. All Rights Reserved.
  
  Contributor(s) :
  
 */

import andromeda.vo.SimpleValueObject;

import ewhiteboard.display.whiteboard.shapes.WhiteBoardShapeDisplay;
import ewhiteboard.plugins.whiteboard.IWhiteBoardPlugin;
import ewhiteboard.tools.whiteboard.IWhiteBoardTool;

import vegas.errors.ClassCastError;
import vegas.errors.NullPointerError;
import vegas.util.ConstructorUtil;

/**
 * This interface determinates the plugins of the whiteboard tool.
 * @author eKameleon
 */
class ewhiteboard.plugins.whiteboard.AbstractWhiteBoardPlugin extends SimpleValueObject implements IWhiteBoardPlugin
{
	
	/**
	 * Creates a new AbstractWhiteBoardPlugin instance.
	 * @param id the id of the plugin object.
	 * @param shape the WhiteboardShapeDisplay constructor reference of the plugin object.
	 * @param tool the IWhiteBoardTool constructor reference of the plugin object.
	 * @param init A generic object containing properties with which to populate the newly instance. If this argument is null, it is ignored.
	 * @throws NullPointerError if the passed-in {@code id} argument is 'null' or 'undefined'.
	 * @throws ClassCastError if the passed-in constructors 'shape' and 'tool' don't implement the good class.
	 */
	public function AbstractWhiteBoardPlugin( id, shape:Function, tool:Function, init:Object ) 
	{
		super( init ) ;
		if ( id != null )
		{
			setID( id ) ;
		}
		else
		{
			throw new NullPointerError( this + " constructor failed if the specified id is 'null' or 'undefined'.") ;
		}
		setShape( shape ) ;	
		setTool( tool ) ; 
	}

	/**
	 * Returns the WhiteboardShapeDisplay constructor of this whiteboard plugin.
	 * @return the WhiteboardShapeDisplay constructor of this whiteboard plugin.
	 */
	public function getShape():Function 
	{
		return _shape ;	
	}
	
	/**
	 * Returns the IWhiteBoardTool constructor of this whiteboard plugin.
	 * @return the IWhiteBoardTool constructor of this whiteboard plugin.
	 */
	public function getTool():Function
	{
		return _tool ;
	}

	/**
	 * Returns the WhiteBoardShapeDisplay constructor of this whiteboard plugin.
	 * @return the WhiteBoardShapeDisplay constructor of this whiteboard plugin.
	 * @throws ClassCastError if the passed-in 'shape' constructor isn't the sub constructor of the good class.
	 */
	public function setShape( clazz:Function ):Void
	{
		if ( ConstructorUtil.isSubConstructorOf( clazz , WhiteBoardShapeDisplay ) )
		{
	 		_shape = clazz ;
		}
		else
		{
			throw new ClassCastError( this + " setTool method failed if the parameter isn't a WhiteBoardShapeDisplay implementation constructor.") ;	
		}
	}

	/**
	 * Returns the IWhiteBoardTool constructor of this whiteboard plugin.
	 * @return the IWhiteBoardTool constructor of this whiteboard plugin.
	 * @throws ClassCastError if the passed-in 'tool' constructor don't implement the good class.
	 */
	public function setTool( clazz:Function ):Void 
	{
		if ( ConstructorUtil.isImplementationOf( clazz , IWhiteBoardTool ) )
		{
			_tool = clazz ;
		}
		else
		{
			throw new ClassCastError( this + " setTool method failed if the parameter isn't a IWhiteBoardTool implementation constructor.") ;	
		}
	}

	private var _shape:Function ;

	private var _tool:Function ;


}